
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "setting.h"
#include "conf.h"

struct setting_t g_setting;

int setting_init()
{
	memset(&g_setting, '\0', sizeof(struct setting_t));	

	return 0;
}


int setting_load(char *file)
{
	if(conf_load(file) == -1) {
		printf("conf load error\n");
		return 0;
	}

	if(conf_number("log_level") > 0) {
		g_setting.log_level = conf_number("log_level");
	} 
	if(conf_number("timeout") > 0) {
		g_setting.timeout = conf_number("timeout");
	}
	if(strlen(conf_string("mail_domain")) > 0) {
		strncpy(g_setting.mail_domain, conf_string("mail_domain"), sizeof(g_setting.mail_domain)-1);
	}
	if(strlen(conf_string("imapd_domain")) > 0) {
		strncpy(g_setting.imapd_domain, conf_string("imapd_domain"), sizeof(g_setting.imapd_domain)-1);
	}
	if(conf_number("imapd_port") > 0) {
		g_setting.imapd_port = conf_number("imapd_port");
	}

	return 0;
}


